package com.test16_内部类;

import org.junit.Test;

/**
 * static定义内部类
 */
public class YootkDemo_03 {

    @Test
    public void test1() {
        // 实例化内部类(static定义的内部类)
        Outer3.Inner3 in = new Outer3.Inner3();
        in.printMessage();
    }

    @Test
    public void test2() {
        IMessage3 message = new EduMessage3();
        message.send("www.yootk.com");
    }
}

class Outer3 {
    private static final String MESSAGE = "沐言优拓：www.yootk.com";

    /**
     * static定义内部类
     * 此时的内部类不在受到外部类实例化对象的影响，所以等同于是一个外部类
     */
    static class Inner3 {
        public void printMessage() {
            System.out.println(Outer3.MESSAGE);
        }
    }
}

interface IMessage3 {
    public void send(String message);

    static interface IChannel3 {     // 外部接口
        public boolean build();
        public void close();
    }

    static abstract class AbstractHandle3 {      // 外部抽象类
        public abstract String addPrefix(String value);
    }

    public static IChannel3 getDefaultChannel() {
        return new InternetChanel3();
    }

    public static AbstractHandle3 getDefaultHandle() {
        return new MessageHandle3();
    }

    class InternetChanel3 implements IMessage3.IChannel3 {    // 内部接口定义内部类

        @Override
        public boolean build() {
            System.out.println("【InternetChannel】创建互联网连接通道...");
            return true;
        }

        @Override
        public void close() {
            System.out.println("【InternetChannel】关闭通道连接...");
        }
    }

    class MessageHandle3 extends AbstractHandle3 {
        @Override
        public String addPrefix(String value) {
            return "【沐言科技】" + value;
        }
    }
}

class EduMessage3 implements IMessage3 {

    @Override
    public void send(String message) {
        IChannel3 channel = IMessage3.getDefaultChannel();
        AbstractHandle3 handle = IMessage3.getDefaultHandle();
        if (channel.build()) {
            System.out.println(handle.addPrefix(message));
            channel.close();
        }
    }
}
